{% extends "base.html" %}

{% block content %}
<div id="content"> 
 
<h2>Problems</h2> 

  {% for prob in problems_list %}
  {# Only display a problem if the current time is past the start time #}
  {% if prob.status != "waiting" %}

  <h3>{{ prob.name }} </h3> 
    <p>Status:  
    {% if prob.status == "open" %} <font color='green'>Open</font> 
    {% else %} {% if prob.status == "closed" %}<font color='red'>Closed</font>
    {% else %} {% if prob.status == "overtime" %}<font color='blue'>Overtime</font>
    {% endif %}{% endif %}{% endif %}</p> 
  

  {# Display message to let the user know their file was submitted successfully #}
  {% if upload and upload_in_time and pname == prob.name %}
  <font color="green"><h4>Your file was submitted successfully</h4></font>
  {% else %}{% if not upload and upload_in_time and pname == prob.name %}
  <font color="red"><h4>There was a problem submitting your file, please try again.</h4></font>
  {% else %} {% if not upload_in_time and pname == prob.name %}
  <font color="red"><h4>The problem has already closed and your submission was not uploaded. Next time be quicker!</h4></font> 
  {% endif %}{% endif %}{% endif %}

  {# Here is the information about the problem #}
  <ul>
    <li>
      <font color="blue">Opens: {{ prob.start_time|date:"H:i" }}</font>,
      <font color="red">Closes {{ prob.close_time|date:"H:i" }}</font>,
      Current time {% now "H:i" %} Time remaining: <em>some cool javascript clock counting down, maybe</em>
    </li>
  <li><p>{{ prob.description }}</p></li>
  
  {# If the current time is less than the close time, display upload box, otherwise show solution #}
  {% if prob.status == "open" or prob.status == "overtime" %}
  <li>
    <form action="/contestron/problems/" method="post" enctype="multipart/form-data">
      {% csrf_token %}
        <input type="file" name="file">
	<input type="hidden" name="probname" value="{{ prob.name }}">
	<input type="submit" name ="Submit">
    </form>
  </li>
  {% else %}
  <li><p>{{ prob.solution }}</p></li>
  {% endif %}
  </ul>
  <hr />
  {% else %}
  <h4>Problem {{ prob.name }} is not yet open and its status is : {{ prob.status }}</h4>
  {% endif %} {# This closes the first if concerning whether the problem is displayed at all #}
  {% endfor %}
</div>
{% endblock content %}
